package coop.tecso.modelo1.util;

import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

public class ProcessExecuteStatement implements Command {

	private Object bean;
	private List<String> beanProperties;
	
	public void execute(Statement statement, String sqlStatement)
			throws SQLException {
		ResultSet rs = null;
		
		try {
			rs = statement.executeQuery(sqlStatement);
			while(rs.next()){
				for (String property : beanProperties){
					Object data = rs.getObject(property);
					BeanUtils.setProperty(bean, property, data);
				
				}
				
			}
		} catch (SQLException e){
			e.printStackTrace();
			throw e;
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}	
		
		
		
		
	}

	public Object getBean() {
		return bean;
	}

	public void setBean(Object bean) {
		this.bean = bean;
	}

	public List<String> getBeanProperties() {
		return beanProperties;
	}

	public void setBeanProperties(List<String> beanProperties) {
		this.beanProperties = beanProperties;
	}

	
	
	
}
